var app = getApp();
var com = require('../../common.js');
Page({
  data: {
    staute: false,
    list: ['全部时间', '本月', '上个月', '半年内', '一年内', '三年'],
    value: 0,
    values: 0,
    lists: ['全部', '已结算', '未结算'],
    info: [],
    tab: '',
    status: ''
  },
  onLoad: function(options) {
    var _this = this
    _this.onListPage()
  },
  onReady: function() {},
  onShow: function() {},
  onHide: function() {},
  onUnload: function() {},
  onPullDownRefresh: function() {},
  onReachBottom: function() {
    var _this = this
    if (_this.data.nextUrl) {
      com.link(_this.data.nextUrl, {}, function(rep) {
        console.log(rep)
        let list = _this.data.info
        for (let i in rep.data.data) {
          list.push(rep.data.data[i])
        }
        _this.setData({
          info: list,
          nextUrl: rep.data.links.next,
        })
      }, "GET")
    }else{
      wx.showToast({
        title: '已加载全部',
        icon:'none'
      })
    }

  },
  // onShareAppMessage: function() {},
  bindt() {
    var _this = this
    setTimeout(() => {
      wx.showModal({
        title: '温馨提示',
        content: '是否打开',
        success(res) {
          if (res.confirm) {
            _this.setData({
              staute: true
            })
          }
        }
      })
    })
  },
  hidend() {
    this.setData({
      staute: false
    })
  },
  onListPage() {
    var _this = this
    com.link(app.link.settlements, {
      tab: _this.data.tab,
      state: _this.data.status
    }, function(rep) {
      console.log(rep)
      _this.setData({
        info: rep.data.data,
        nextUrl: rep.data.links.next,
      })
    }, "GET")
  },
  onTapChang(e) {
    var _this = this,
      id = e.detail.value
    console.log(e)
    if (id == 0) {
      var value = ''
    } else if (id == 1) {
      var value = 'month'
    } else if (id == 2) {
      var value = 'lastmonth'
    } else if (id == 3) {
      var value = 'half'
    } else if (id == 4) {
      var value = 'one'
    } else if (id == 5) {
      var value = 'year'
    }
    _this.setData({
      value: id,
      tab: value
    })
    _this.onListPage()
  },
  onTapChangs(e) {
    var _this = this,
      id = e.detail.value
    console.log(e)
    if (id == 0) {
      var value = ''
    } else if (id == 1) {
      var value = 'pay'
    } else if (id == 2) {
      var value = 'unpay'
    }
    console.log(e)
    _this.setData({
      values: e.detail.value,
      status: value
    })
    _this.onListPage()
  },
  jumpPage(e) {
    wx.navigateTo({
      url: "/pages/serialPage/serialPage?id=" + e.currentTarget.id,
    })
  }
})